package com.foodservice.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.foodservice.bean.Food;
import com.foodservice.bean.FoodType;
import com.foodservice.dao.FoodDao;

public class FoodDaoImpl implements FoodDao{

	private SessionFactory sessionFactory = null;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void addFood(Food food) {
		// TODO Auto-generated method stub
		Session s = sessionFactory.getCurrentSession();
		s.beginTransaction();
	    s.save(food);
		s.getTransaction().commit();
	}

	public void deleteFood(Food food) {
		// TODO Auto-generated method stub
		
	}

	public void updateFood(Food food) {
		// TODO Auto-generated method stub
		
	}

	public List<Food> queryAllFood() {
		// TODO Auto-generated method stub
		Session s = sessionFactory.getCurrentSession();
		List<Food> foods = s.createQuery("from Food").list();
		s.close();
		return foods;
	}

	public List<Food> queryFoodByType(FoodType foodType) {
		// TODO Auto-generated method stub
		Session s = sessionFactory.getCurrentSession();
		List<Food> foods = s.createQuery("from Food where foodType_id = ?").setInteger(0, foodType.getId()).list();
		return foods;
	}

	public List<Food> queryFoodByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

}
